<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增告警规则信息')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-node-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">告警规则名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="ruleName" id="ruleName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">规则类型：</label>
				<div class="col-sm-8">
					<select id="ruleType" name="ruleType" class="form-control" th:with="type=${@dict.getType('alarm_rule_list')}" onchange="changeSelect()" required>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">事件编号：</label>
				<div class="col-sm-8">
					<!--<select id="eventCode" name="eventCode" class="form-control" th:with="type=${@dict.getType('alarm_rule_monitor_agent')}" required>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>-->
					<select id="eventCode" name="eventCode" class="form-control" required>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">告警阈值：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="threshold" id="threshold" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">告警等级：</label>
				<div class="col-sm-8">
					<select id="level" name="level" class="form-control" th:with="type=${@dict.getType('alarm_level')}" required>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">连续次数：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="continuousNumber" id="continuousNumber" value="1" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">机器是否参与：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
						<input type="checkbox" id="machineParticipation">
						<span></span>
					</label>
				</div>
			</div>
			<!--<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>-->
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/alarmRule";

		$(function () {
			changeSelect();
		});

		$("#form-node-add").validate({
			onkeyup: false,
			rules:{
			},
			messages: {
		    },
		    focusCleanup: true
		});

		function submitHandler() {
	        if ($.validate.form()) {
				var data = $('#form-node-add').serializeArray();
				var machineParticipation = $("input[id='machineParticipation']").is(':checked') == true ? 1 : 0;
				data.push({"name": "machineParticipation", "value": machineParticipation});
				$.operate.save(prefix + "/add", data);
	        }
	    }

		function changeSelect() {
			//获取被选中的option值
			var ruleType = $('#ruleType').find('option:selected').val();
			$('#eventCode').empty();
			$.get(ctx + "system/dict/data/getType?dictType=" + ruleType, function (data) {
				var list = data.data;
				//遍历回传的数据添加到二级select
                $.each(list, function (key, info) {
                    var option = '<option value="' + info.dictValue + '">' + info.dictLabel + '</option>'
                    $("#eventCode").append(option)
                });
			});
		}

	</script>
</body>
</html>
